<?php
    class Admin_support extends Admin_Controller{
        function __construct(){
            parent::__construct();
            $this->load->model('Support_m');
            $this->_data['sidebar']="support";
        }
       function index(){
           $this->list_support_account();
        }
      
             
         function list_support_account(){
            is_admin();
            $this->_data['account'] = $this->Support_m->get_support_account();
            $this->_data['page_title'] = "Support account";
            $this->display_admin('admin/information/list_yahoo_account');
            }
            
   
    
    function delete_support_account($id) {
        is_admin();
        $query = $this->Support_m->delete_support_account($id);
        if ($query)
            $this->session->set_flashdata('error', "Account hỗ trợ được xóa thành công");
        else
            $this->session->set_flashdata('error', "Xóa account hỗ trợ thất bại !");
        redirect('admin_support/list_support_account');
    }
    
    function delete_multi_support_accounts() {
        is_admin();
        $list = "";
        $adelete = $this->input->post('delete');
        $N = count($adelete);
        for ($i = 0; $i < $N; $i++) {
            if ($adelete[$i] != ""
                )$list = $list . ',' . $adelete[$i];
        }
        $list = '(' . substr($list, 1) . ')';

        $query = $this->Support_m->delete_multi_support_accounts($list);
        if ($query)
            $this->session->set_flashdata('error', "Account hỗ trợ được xóa thành công");
        else
            $this->session->set_flashdata('error', "Xóa account hỗ trợ thất bại !");
        redirect('admin_support/list_support_account');
    }
    
     function add_support_account() {
        is_admin();
        $config = array(
            array(
                'field' => 'account',
                'label' => 'Support account',
                'rules' => 'required'
            ),
            array(
                'field' => 'name',
                'label' => 'Họ tên',
                'rules' => 'required'
            )
            
        );
        $this->form_validation->set_rules($config);
        if ($this->input->post('submit')) {
            if ($this->form_validation->run()) {
                $data = array(
                    'account' => $this->input->post('account'),
                    'name' => $this->input->post('name')
                  
                );
                $query = $this->Support_m->add_support_account($data);
                if ($query)
                    $this->session->set_flashdata('error', "Thêm account hỗ trợ thành công!");
                else
                    $this->session->set_flashdata('error', "Thêm account hỗ trợ thất bại !");
                redirect('admin_support/list_support_account');
            }
        }
        $this->display_admin('admin/information/add_support_account');
    }
}
?>
